<template>
<!--  {{timezone}}-->
<!--  {{localTimeZone}}-->
<!--  {{ timestampToDateTime(convert2LocalTimeZone(timeStr))}}-->
<!--  {{userStore.timezone}}{{timestampToDateTime(time)}}-->
<!--  {{timeStr}} {{moment.tz.guess(true)}}-->
<!--  {{moment(timeStr).tz(localTimeZone).format('YYYY-MM-DD HH:mm:ss')}}-->
<!--  {{timestampToDateTime(convert2LocalTimeZone(timeStr))}}-->
<!--  {{timestampToDateTime(modelValue)}}-->
<!--  {{ timestampToDateTime(time)}} {{"ZoneOffset.UTC"+timeStr}}-->
<!--  {{timeStr}} {{timestampToDateTime(modelValue)}}-->
  <n-date-picker
      :actions="['clear', 'confirm']"
      v-model:formatted-value="timeStr"
      type="datetime"
      clearable
  />
</template>
<script lang="ts" setup>
import {TaskLogData, TimeMentionModal} from "@/views/model/model";
import {computed, defineComponent, onMounted, ref, watch} from "vue";
import moment from 'moment-timezone'
import useUserStore from "@/store/modules/user";
import {timestampToDateTime, timeToTimestamp} from "@/utils";
import {post, Response} from "@/api/http";
import {convertStr2Time, getLifeModeItemSelect} from "@/api/url";
const userStore = useUserStore()
const timezone = computed(()=>{
  return userStore.timezone;
})

// 父组件数据
const props = defineProps(['time'])
const emit = defineEmits(['update:time'])
// emit('update:time', title.value)
const modelValue = computed({
  get: () => props.time?props.time:Date.now(),
  set: val => emit("update:time", val),
});

const localTimeZone = moment.tz.guess(true)
// console.log(userStore.timezone, localTimeZone.value, moment("2023-12-31 14:27:04").tz(userStore.timezone).format('YYYY-MM-DD HH:mm:ss'),"+++++++++++++++++")
const covertTime2TimeZoneStr = (time:number)=>{
  const localTime  = moment.tz(timestampToDateTime(time), localTimeZone);
  // console.log(localTime,"+++++++++++++++++1")
  const losAngeles = localTime.clone().tz(timezone.value);
  // console.log(losAngeles,"+++++++++++++++++2")
  return losAngeles.format('YYYY-MM-DD HH:mm:ss')
}
const time = ref(Date.now())
const convert2LocalTimeZone = (str:string)=>{
  const localTime  = moment.tz(str, timezone.value).valueOf();
  return localTime;
}

const timeStr = ref(timestampToDateTime(Date.now())) //ref(covertTime2TimeZoneStr(Date.now()))
onMounted(()=>{
  timeStr.value = covertTime2TimeZoneStr(modelValue.value)
})
watch(timeStr,async ()=>{
  // emit('update:time', convert2LocalTimeZone(timeStr.value))
  if(timeStr.value) modelValue.value = convert2LocalTimeZone(timeStr.value)
  else modelValue.value = 0
})


</script>